package com.songkun.template.ui.activity;

import android.databinding.DataBindingUtil;
import android.widget.Toast;

import com.songkun.template.R;
import com.songkun.template.databinding.ActivityMainBinding;
import com.songkun.template.entity.CheckVersionBean;
import com.songkun.template.refrofit.RefrofitFactory;
import com.songkun.template.refrofit.service.CheckVersion;
import com.songkun.template.ui.base.CommonActivity;
import com.songkun.template.utils.ILog;
import com.songkun.template.utils.eventObj.VoidEvent;

import org.greenrobot.eventbus.Subscribe;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;


public class MainActivity extends CommonActivity {


    private ActivityMainBinding mBinding;


    @Override
    protected void initHeader() {
        isTitleLayoutShow(true);
    }


    @Override
    protected void initContentView() {
        mBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.activity_main, null, false);
        setContentView(mBinding.getRoot());


        mBinding.tv.setOnClickListener(v -> Toast.makeText(MainActivity.this, "点击了我", Toast.LENGTH_SHORT).show());
    }


    @Override
    protected void initData() {
        CheckVersion checkVersion = RefrofitFactory.create(CheckVersion.class);

        checkVersion.checkVersion("2")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<CheckVersionBean>() {
                    @Override
                    public void call(CheckVersionBean checkVersionBean) {
                        ILog.d(checkVersionBean.data.desc);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        ILog.e("出错了|" + throwable.getMessage());
                    }
                });
    }


    @Subscribe
    public void onInvalid(VoidEvent event) {}


    @Override
    protected void onDestroy() {
        super.onDestroy();


    }
}
